package cn.itcast.email;


import cn.itcast.utils.MailUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.util.Map;

public class EmailConsumer implements MessageListener{


    @Override
    public void onMessage(Message message) {

        try {
            byte[] body = message.getBody();

            Map<String,String> emailMap = JSON.parseObject(body, Map.class);

            String to = emailMap.get("to");
            String subject = emailMap.get("subject");
            String context = emailMap.get("context");

            MailUtil.sendMsg(to,subject,context);

            System.out.println("邮件发送成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
